package com.yanqu.road.server.cmd.player;

import com.yanqu.road.entity.config.goods.GoodsBagInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.common.CommonProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.server.manger.system.CommonMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

@Cmd(code = Protocol.S_GET_BOX_DETAIL, desc = "请求宝箱内容详情")
public class GetItemBoxDetailCmd extends AbstractCommand {

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		CommonProto.GetBoxDetailReqMsg reqMsg = CommonProto.GetBoxDetailReqMsg.parseFrom(packet.getBytes());
		int boxId = reqMsg.getBoxId();
		List<GoodsBagInfo> boxAllBagInfoList = CommonMgr.getBoxAllBagInfoList(boxId);

		CommonProto.GetBoxDetailRespMsg.Builder respMsg = CommonProto.GetBoxDetailRespMsg.newBuilder();
		for (GoodsBagInfo goodsBagInfo : boxAllBagInfoList) {
			CommonProto.BoxItemInfoTemp.Builder builder = CommonProto.BoxItemInfoTemp.newBuilder();

			builder.setGoodsId(goodsBagInfo.getGoodsId());
			builder.setRandomType(goodsBagInfo.getRandomType());
			builder.setMinNum(goodsBagInfo.getMinNum());
			builder.setMaxNum(goodsBagInfo.getMaxNum());
			builder.setProbability(goodsBagInfo.getRandomWeight());
			builder.setIsNotice(goodsBagInfo.getNotice());

			respMsg.addBoxItemList(builder);
		}

		player.sendPacket(ClientProtocol.U_GET_BOX_DETAIL, respMsg);
	}

	@Override
	public void sendData(GamePlayer player) {

	}
}
